<?php
    if (!defined('EXPONENT')) exit('');
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate","upload","delete","meeting","meeting_delete","meeting_assistant"),exponent_core_makeLocation("profilemodule","_syscore","")))
    {
        $id=0;
        if (isset($_REQUEST['id']))
            $id=intval($_REQUEST['id']);
        
        $template=new template("profilemodule","_profile_edit",$loc);
        
        $content=$db->selectObject('profilemodule_profile','user_id='.$id);
                
        if (!$content)
        {
            $content = profilemodule::_profile_init_default();
            $sql="SELECT * FROM {$db->prefix}user WHERE is_locked=0 AND id NOT IN (SELECT user_id FROM {$db->prefix}profilemodule_profile)";
            $data =$db->selectObjectsBySql($sql);
            $dropdown = null;
            foreach ($data as $k=>$v)
                $dropdown[$v->id]=$v->firstname." ".$v->lastname." ({$v->email})";
            $template->assign("users_list", $dropdown);
            $max_client_id=$db->max('profilemodule_profile','id');
            $content->client_id='90'.($max_client_id+1);
        }
       
       
        $template->assign('user',$content);
        $template->register_permissions(array('administrate',"configure"),$loc);
        $template->output();
    }
    else
    {
        exponent_http_error(403);
    }
?>
